<template>

  <div style="padding-top:100px;">

    <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>管理员登录</span>
    </div>

<el-input v-model="userinfo.username" placeholder="用户名"></el-input>

<el-input v-model="userinfo.password" type="password" placeholder="密码" style="margin-top:20px;"></el-input>
<el-button type="primary" style="margin:20px auto;width:60%;display:block;" @click="validatelogin">登 录</el-button>
<el-alert
  :title=emptytxt
  type="error"
  show-icon
  v-show="error"
  >
</el-alert>

</el-card>

  </div>


</template>
<script>
import axios from "axios";
export default{
  name:"login",
  data:function(){
  return{
    userinfo:{
      username:"",
      password:""
    },
    emptytxt:"",
    error:false
  }
  },methods:{
    validatelogin:function(){
      var that=this;
      if(this.userinfo.username==""||this.userinfo.password==""){
          this.emptytxt="用户名或密码不能为空";
          this.error=true;
      }else{
        var apiurl=this.GLOBAL.apiurl;
        axios.get(apiurl+"/login",{params:this.userinfo})
              .then(function(res){

              if(res.data.length==0){
                that.emptytxt="用户名或密码错误";
                that.error=true;
              }else{
                var username=res.data[0].username
                that.$cookieStore.setCookie("username",username,7);
                that.$router.push({path:'/Home'});
              }


              })
              .catch(function(error){
              console.log(error);
        })
      }

    }
  }
}
</script>
<style>
body{
background:#e5e5e5;
}
.box-card{
width:30%;
margin:0px auto;
margin-top:20px;
}
</style>
